# -*- coding: utf-8 -*-
"""
Created on Sun Jun 28 14:45:28 2020

@author: Lenovo
"""
file_name = input("请输入你要查询的文件夹：  ")
com=[1,2,31,32,41,42,5,6,7,8,9,101,102,11,12,131,132,141,142,15,16]
# com=[101,102]
# com=[1,2,31,32]
list_2=[]
import csv
num1=0
for m in com:  
    print(m)     
    f = open(file_name+'/'+str(m)+'.csv','r',encoding='UTF-8')  # 打开原文件
    reader=csv.reader(f)
    list_1 = []
    list_f=list(reader)[2:-1][::-1]  #  去掉数据头尾不需要的值,倒置
    for num in list_f:
        list_1.append(float(num[1]))  #  剔除日期，提取电量数据
    if m == 1:
        num1=len(list_1)
    num2=len(list_1)
    if num2<num1:
        while num2 < num1+1:
            list_1.append(0)
            num2+=1
    if m != 16:
        n=0
        l2=[]
        while n < len(list_1)+1:
            if n % 3 == 0 and n > 2:
                l = []
                l.append(list_1[n-3])
                l.append(list_1[n-2])
                l.append(list_1[n-1])
                s=round(sum(l)/1000,3)
                l2.append(s)
            n+=1
        if m not in [32,42,102,132,142]:
            list_2.append(l2)
        else:
            n = 0
            for N in l2:
                list_2[-1][n]=list_2[-1][n]+l2[n]
                n+=1
    else:
        l2=[]
        for n_16 in list_1:
            l2.append(round((n_16*2.98/1000),3))  
        list_2.append(l2)
list_E=[]
m=len(list_2[0])
n=0
while n < m:
    list_G=[]
    for list_F in list_2:
        list_E.append(list_F[n:n+96])
        list_G.append(list_F[n:n+96])
    n1 = 0
    list_sum=[]
    while n1 < 96:
        list_s=[]
        for n2 in list_G:
            list_s.append(n2[n1])
        list_sum.append(sum(list_s))
        n1+=1
    list_E.append(list_sum)
    n+=96
f1=open(file_name+'数据采集.csv','w',newline='')
writer=csv.writer(f1)
writer.writerows(list_E) #若不加[]，数字会被作为字符串一个一个写入表格
f1.close()
print("haole ")
     
